package consolemir;

import java.util.LinkedList;

public class Menu {
	private LinkedList<Option> options;
	private String title;
	
	public Menu(String title) {
		this.options = new LinkedList<Option>();
		this.title = title;
	}

	public void addOption(Option o) {
		this.options.add(o);
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(this.title);
		sb.append("\n");
		for (Option o : this.options) {
			sb.append(o.toString());
			sb.append("\n");
		}
		return sb.toString();
	}

	public Object execute(char c, Object obj) {
		for (Option o : this.options) {
			if (o.matches(c)) {
				return o.execute(obj);
			}
		}
		return null;
	}

	public LinkedList<Character> getOptionList() {
		LinkedList<Character> l = new LinkedList<Character>();
		for (Option o : this.options) {
			l.add(o.getHotKey());
		}
		return l;
	}

}
